<template>
    <div class="template-index-Lu">
      <commpVxeTable
        :key="reCommpVxeTable"
        :conditionBtnRow="true"
        :config="dataTableConfig"
        :columns="columnsVxe"
        :formItem="formItem"
        @checkboxChange="checkboxChange"
        ref="administrativeOffice"
        @searchEvent="searchEvent"
        @resetEvent="resetEvent"
        >
          <template v-slot:operation_fxm="{row}" data-desc="姓名">
            <span style="padding-right: 21;" v-if="row.fxm.length == 2">
                <span v-for="(trem,tI) in row.fxm.split('')" :key="tI" >
                    {{trem}}
                    <span v-if="tI+1 !== row.fxm.split('').length">&nbsp;&nbsp;</span>
                </span>
            </span>
            <span style="padding-right: 21;" v-else>{{ row.fxm }}</span>
        </template>
          <template v-slot:externalOperations="{data}"  >
              <vxe-form-item>
                  <template>
                      <a-button class="blue-btn" @click="clickAdd">出差申请</a-button>
                  </template>
              </vxe-form-item>
              <vxe-form-item>
                  <template>
                      <a-button class="red-btn" @click="deleteList">批量删除</a-button>
                  </template>
              </vxe-form-item>
          </template>
          <template v-slot:time1_btn="{row}" data-desc="出差开始时间">
              <span>
              {{ row.fccksrq +' '+ row.fcckssj }}
              </span>
          </template>
          <template v-slot:time2_btn="{row}" data-desc="出差结束时间">
              <span>
              {{ row.fccjsrq +' '+ row.fccjssj }}
              </span>
          </template>
          <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
              <a-form layout="inline" class="search-form" >
              <a-form-item>
                  <a-button class="blue-btn" type="primary" @click="reviseClick(row)">办理</a-button>
              </a-form-item>
              <a-form-item>
                  <a-popconfirm
                      title="您确定要删除这条申请吗?"
                      ok-text="确定"
                      cancel-text="取消"
                      @confirm="deleteClick(row)"
                      @cancel="cancel"
                      >
                          <a-button class="red-btn">删除</a-button>
                  </a-popconfirm>
              </a-form-item>
              <a-form-item>
              </a-form-item>
              </a-form>
          </template>
          </commpVxeTable>
          <applicationForm ref="applicationForm" :stepNums="stepNums" :linkName="linkName" :formData="formData" @success="success"></applicationForm>
      </div>
  </template>
  <script>
  import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
  import assessCheckApi from './service/api.js'
  import {deleteLgqsFlowJob,queryJobByJobId,} from './service/index'
  import applicationForm from './applicationForm'
  export default {
    components: {
      commpVxeTable,
      applicationForm
    },
    props:{
      linkName:{
        type:String,
        default:'',
        required:false,
      },
      stepNum:{
        type:String,
        default:'',
        required:false,
      }
    },
    data() {
      return {
        reCommpVxeTable: '',
        dataTableConfig: {
          api: assessCheckApi.list,
          rowId: 'id',
          urlType: true,
          paramet: {
            fhjmc: this.linkName,
          }
        },
        columnsVxe: [
          {
            type: 'checkbox',
            width: 60,
            fixed: 'left'
          },{
            title: '姓名',
            field: 'fxm',
            width: 100,
            titleInterval:true,
            slots: {
                header:'data1_header',
                default:'operation_fxm',
            }
          },{
            title: '出差事由',
            field: 'fccsy',
          },{
            title: '出差开始日期',
            field: 'fccksrq',
            width: 150,
            slots: {
              default: 'time1_btn',
            },
          },{
            title: '出差结束日期',
            field: 'fccjsrq',
            width: 150,
            slots: {
              default: 'time2_btn',
            },
          },{
            title: '出差地点',
            field: 'fccdd',
          },{
            title: '填报时间',
            field: 'ftbsj',
          },{
            title: '退回原因',
            field: 'fthyj',
          },{
            title: '操作',
            field: 'jobid',
            width:200,
            titleInterval:true,
            slots: {
            // 使用插槽模板渲染
            header:'data2_header',
              default: 'operation_btn',
            },
          }
        ],
        formItem: [
          {
            label: '出差事由',
            model: 'fccsy',
          },
        ],
        jobidList: [],
        formData: {},
        stepNums: 0,
      }
    },
    created() {
      this.stepNums = Number(this.stepNum)
    },
    methods: {
      // 勾选
      checkboxChange(val){
        //console.log('已选择',val)
        this.jobidList = []
        if(val.length){
          val.forEach(item => {
              this.jobidList.push(item.jobid)
          });
        }
      },
      // 搜索
      searchEvent(){
        this.dataTableConfig.paramet = {
            ...this.dataTableConfig.paramet,
        }
      },
      // 重置
      resetEvent(){
        this.dataTableConfig.paramet = {
            ...this.dataTableConfig.paramet,
        }
      },
      clickAdd(){
        this.$nextTick(_ => {
          this.$refs.applicationForm.applicationFormVisible = true
        })
      },
      // 弹窗提交成功
      success(){
        // 刷新表格 清空id数组
        this.$refs.administrativeOffice.resetEvent()
        this.jobidList = []
      },
      // 点击办理
      reviseClick(row){
        //console.log('办理',row)
        this.formData = {
          ...row,
          id: row.oaid
        }
        this.$nextTick(_ => {
            this.$refs.applicationForm.applicationFormVisible = true
        })
        // let jobid = row.jobid
        // queryJobByJobId({jobid:jobid}).then(res => {
        //   if(res.code == 200) {
        //     this.formData.id = res.result.sqsx.id
        //     //console.log(this.formData)
        //     //console.log(this.formData.id)
        //     this.$nextTick(_ => {
        //       this.$refs.applicationForm.applicationFormVisible = true
        //     })
        //   }
        // })
      },
      // 删除
      deleteClick(row){
          deleteLgqsFlowJob({jobids:row.jobid}).then(res => {
              //console.log(res)
              if(res.code == 200){
                  this.reCommpVxeTable = Date.now()
                  this.$message.success(res.message)
              } else {
                  this.$message.warning(res.message)
              }
          })
      },
      cancel(e) {
          //console.log(e);
      },
      // 批量删除
      deleteList(){
        var that = this
        if(that.jobidList.length == 0){
          that.$message.warning('请选择删除项目')
        } else {
          that.$confirm({
            title: '您确定要删除这些申请吗?',
            content: '',
            okText: '确定',
            okType: 'danger',
            cancelText: '取消',
            onOk() {
              let list = that.jobidList.toString()
              //console.log(list)
              deleteLgqsFlowJob({jobids:list}).then(res => {
                //console.log(res)
                if(res.code == 200){
                  that.reCommpVxeTable = Date.now()
                  that.$message.success(res.message)
                } else {
                  that.$message.warning(res.message)
                }
              })
            },
            onCancel() {
              //console.log('Cancel');
            },
          });
        }
      },
    }
  }
  </script>
  <style>
  @import url('../../css/oaClass.css');
  </style>
